import os

class FilenameCleaner:
    """
    批量删除文件名中的指定字符串
    """

    def __init__(self, folder_path, string_list):
        """
        :param folder_path: 目标文件夹
        :param string_list: 需要删除的字符串列表
        """
        self.folder_path = folder_path
        self.string_list = string_list

    def clean_filename(self, filename):
        """
        删除文件名中的指定字符串
        """
        new_filename = filename
        for s in self.string_list:
            new_filename = new_filename.replace(s, "")
        return new_filename

    def process(self):
        """
        遍历文件夹，批量清理文件名
        """
        for filename in os.listdir(self.folder_path):
            old_path = os.path.join(self.folder_path, filename)
            if not os.path.isfile(old_path):
                continue

            new_filename = self.clean_filename(filename)
            if new_filename != filename:
                new_path = os.path.join(self.folder_path, new_filename)
                os.rename(old_path, new_path)
                print(f"重命名: {filename} -> {new_filename}")


if __name__ == "__main__":
    folder = input("请输入文件夹路径: ").strip()
    strings_input = input("请输入要删除的字符串（用逗号分隔）: ").strip()
    string_list = [s.strip() for s in strings_input.split(",")]

    cleaner = FilenameCleaner(folder, string_list)
    cleaner.process()
